package com.example.zqm.git72.Fragment;
import android.app.Activity;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;

import com.example.zqm.git72.R;

/**
 * A simple {@link Fragment} subclass.
 */
public class BaseFragment extends Fragment {
   private SharedPreferences sp;
    protected FragmentManager childManager;
    private FragmentTransaction transaction;
    public Context context;
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity);
        context=getActivity();
    }
//   public int getUser_id(){
//        sp = getActivity().getSharedPreferences("userInfo",Context.MODE_PRIVATE);
//       return sp.getInt("user_id",2);
//
//   }


    @Override
    public void onCreate(@Nullable Bundle savedInstanceState){
        super.onCreate(savedInstanceState);
        childManager = getChildFragmentManager();
    }
    protected  void addFragment(Fragment fragment){
        transaction =childManager.beginTransaction();
        transaction.add(R.id.fragment_container,fragment);
        transaction.commit();
    }

    @Override
    public  void onAttach(Context context){
        super.onAttach(context);
        this.context = context;

    }
    protected void replaceFragment(Fragment fragment){
        transaction =childManager.beginTransaction();
        transaction.replace(R.id.fragment_container,fragment);
        transaction.commit();
    }

}
